﻿namespace NiuX.AspNetCore;

public class App
{
    public static WebApplication WebApplication { get; set; }

    public static TService GetService<TService>()
    {
        return (TService)ServiceProvider.GetService(typeof(TService));
    }

    public static async Task ExecuteInScope(Func<IServiceProvider, Task> func)
    {
        await using var scope = ServiceProvider.CreateAsyncScope();
        await func(scope.ServiceProvider);
    }

    public static IServiceProvider ServiceProvider => WebApplication.Services;

    public static string DefaultConnectionString { get; set; }
}